package com.samphanie.auiu.admin.controller;

import com.samphanie.auiu.admin.service.ISysRoleResourceService;
import com.samphanie.auiu.common.utils.ApiResponse;
import com.samphanie.auiu.mbg.model.SysRoleResource;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 角色资源关系Controller
 *
 * @author zsy
 * @date 2021-05-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/role_resource")
public class SysRoleResourceController {

    private final ISysRoleResourceService sysRoleResourceService;

    /**
     * 查询角色资源关系列表
     */
    @GetMapping("/list")
    public ApiResponse<?> list(@RequestParam Map<String, Object> query) {
        return ApiResponse.success(sysRoleResourceService.listPage(query));
    }

    /**
     * 获取角色资源关系详细信息
     */
    @GetMapping(value = "/{id}")
    public ApiResponse<?> getInfo(@PathVariable("id") Long id) {
        return ApiResponse.success(sysRoleResourceService.getById(id));
    }

    /**
     * 新增角色资源关系
     */
    @PostMapping
    public ApiResponse<?> add(@RequestBody SysRoleResource sysRoleResource) {
        sysRoleResourceService.save(sysRoleResource);
        return ApiResponse.success("新增成功");
    }

    /**
     * 修改角色资源关系
     */
    @PutMapping
    public ApiResponse<?> edit(@RequestBody SysRoleResource sysRoleResource) {
        sysRoleResourceService.updateById(sysRoleResource);
        return ApiResponse.success("修改成功");
    }

    /**
     * 删除角色资源关系
     */
    @DeleteMapping("/{ids}")
    public ApiResponse<?> remove(@PathVariable Long[] ids) {
        sysRoleResourceService.removeByIds(Arrays.asList(ids));
        return ApiResponse.success("删除成功");
    }
}
